<?php
/**
 * Created by PhpStorm.
 * User: geyouwen
 * Date: 16/9/12
 * Time: 上午9:37
 */

namespace Home\Model;


use Think\Model;

class PasswordSecretModel extends Model
{

    /**
     * 邮件发送函数
     */
    public function sendMail($to, $title, $content) {

        Vendor('PHPMailer.PHPMailerAutoload');
        $mail = new \PHPMailer(); //实例化
        $config = S('email_config');
        if(!$config)
        {
            //配置缓存
            $config = D('settings')->getEmailSettings();
            S('email_config', $config);
        }
        $mail->IsSMTP(); // 启用SMTP
        $mail->Host= $config['setting_email_host']['data']; //C('MAIL_HOST'); //smtp服务器的名称（这里以QQ邮箱为例）
        $mail->SMTPAuth = true; //启用smtp认证
        $mail->Username = $config['setting_email_username']['data']; //你的邮箱名
        $mail->Password = $config['setting_email_password']['data'] ; //邮箱密码
        $mail->From = $config['setting_email_username']['data']; //发件人地址（也就是你的邮箱地址）
        $mail->FromName = $config['setting_email_from']['data']; //发件人姓名
        $mail->AddAddress($to,"尊敬的客户");
        $mail->WordWrap = 100; //设置每行字符长度
        $mail->IsHTML(true); // 是否HTML格式邮件
        $mail->CharSet=$config['setting_email_charset']['data']; //设置邮件编码
        $mail->Subject =$title; //邮件主题
        $mail->Body = $content; //邮件内容
        return($mail->Send());
    }
}